{extend name="../../admin/view/main"}

{block name="content"}
{include file='shop/goods/formstyle'}
<form autocomplete="off" class='layui-form layui-card' data-auto="true" id="GoodsForm" method="post" onsubmit="return false;">
    <div class="layui-card-body padding-40 padding-bottom-20">


        <div class="layui-form-item relative block">
            <span class="color-green font-w7 label-required-prev">所属公司分类</span>
            <div class="layui-row">
                {notempty name='companies'}
                <label class="layui-col-xs6">
                    <select class="layui-select" name="company_id" onchange="set_cate(this)">
                        <option value="0">选择公司</option>
                        {foreach $companies as $company}
                        {if !empty($vo) and $vo.company_id eq $company.id}
                        <option selected value="{$company.id}">{$company.name}</option>
                        {else}
                        <option value="{$company.id}">{$company.name}</option>
                        {/if}
                        {/foreach}
                    </select>
                </label>
                {/notempty}
                {notempty name='cates'}
                <label class="layui-col-xs6">
                    <select class="layui-select" name="cate_id">
                        <option value="0">选择分类</option>
                        {foreach $cates as $cate}
                        {if !empty($vo) and $vo.cate_id eq $cate.id}
                        <option selected value="{$cate.id}">{$cate.name}</option>
                        {else}
                        <option value="{$cate.id}">{$cate.name}</option>
                        {/if}
                        {/foreach}
                    </select>
                </label>
                {/notempty}
            </div>
        </div>

        <label class="layui-form-item block relative">
            <span class="color-green font-w7">产品名称</span>
            <span class="color-desc margin-left-5">Goods Name</span>
            <input class="layui-input" name="name" placeholder="请输入产品名称" required value="{$vo.name|default=''}">
        </label>

        <div class="goods-item-box">
            <div class="layui-clear layui-row">
                <div class="layui-col-xs3 layui-col-lg3">
                    <fieldset>
                        <legend><span class="layui-badge think-bg-violet">投资时间类型</span></legend>
                        <div class="layui-form-item">
                            {foreach ['月','季','年','天'] as $k=>$v}
                            {if (isset($vo.time_type) and $vo.time_type eq $k+1)}
                            <input checked name="time_type" title="{$v}" type="radio" value="{$k+1}">
                            {else}
                            <input name="time_type" title="{$v}" type="radio" value="{$k+1}">
                            {/if}{/foreach}
                        </div>
                    </fieldset>
                </div>
                <div class="layui-col-xs3 layui-col-lg3">
                    <fieldset>
                        <legend><span class="layui-badge think-bg-violet">投资时间数值</span></legend>
                        <label class="layui-form-item">
                            <input class="layui-input" data-blur-number="0" name="time_number" placeholder="" value="{$vo.time_number|default=0}">
                        </label>
                    </fieldset>
                </div>
                <div class="layui-col-xs3 layui-col-lg3">
                    <fieldset>
                        <legend><span class="layui-badge think-bg-violet">年利率</span></legend>
                        <label class="layui-form-item">
                            <input class="layui-input" data-value-min="1" data-blur-number="2" data-value-max="100" name="annual_rate"  placeholder="请输入年利率" value="{$vo.annual_rate|default=0}">
                            <span class="help-block">限制1-100</span>
                        </label>
                    </fieldset>
                </div>
                <div class="layui-col-xs3 layui-col-lg3">
                    <fieldset>
                        <legend><span class="layui-badge think-bg-violet">返息规则</span></legend>
                        <div class="layui-form-item">
                            <input {if (isset($vo.return_rule) and $vo.return_rule eq 1)}
                                   checked
                                   {/if}
                                   name="return_rule" title="按月返" type="radio" value="1">
                            <input {if (isset($vo.return_rule) and $vo.return_rule eq 2)} checked
                                   {/if} name="return_rule" title="到期返" type="radio" value="2">
                        </div>
                    </fieldset>
                </div>
            </div>
        </div>


        <label class="layui-form-item block">
            <span class="font-w7 color-green">简介描述</span>
            <textarea class="layui-textarea" name="remark" placeholder="请输入产品简介描述">{$vo.remark|default=''|raw}</textarea>
        </label>

        <div class="hr-line-dashed margin-top-40"></div>
        {notempty name='vo.id'}<input name="id" type="hidden" value="{$vo.id}">{/notempty}

        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-danger" onclick="pageBack()" type="button">取消编辑</button>
            <button class="layui-btn" type="submit">保存产品</button>
        </div>
    </div>
</form>
{/block}

{block name='script'}

<script>
    /*! 表单初始化 */
    window.form.render();

    var originalCates = {:json_encode($cates)};
    function set_cate(company_id) {

        var pv,innerHtml;

        pv = company_id.value;
        innerHtml = '<option value="0">选择分类</option>';
        if (pv == 0) return;

        $.each(originalCates, function(key, val) {
            if(val.company_id == pv){
                innerHtml+= '<option value="'+val.id+'">'+val.name+'</option>'
            }
        });

        $("select[name='cate_id']").html(innerHtml)

    }
    function pageBack () {
        $.msg.confirm('确定要取消编辑吗？', function (index) {
            history.back(), $.msg.close(index);
        });
    };


</script>
{/block}